
<html>
 
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="public/css.css" rel="stylesheet" type="text/css" />
        
        <title>Huy Bee</title>
    </head>
    <body>
        <div class="chung">
        <h1 align="center">Words</h1>
<?php
require_once './class/db.php';
require_once './class/keywords.php';
require_once './class/words.php';
?>
<?php
//Em chua lam tinh nang: edit cho working dung ko?
//da
//:p 0 diem nhe' :adx
//ok?
//tu tu thay oi
//:D co 1 tuan roi em oi :D, cai nay o web1 em lam roi ma
$keywords = new words();
$list= $keywords->selects();
?>
 <div class="hinh"></div> 
 <div class="menu">
 <ul>
     <li>
         <a href="#">Trang Chủ</a>
     </li>
      <li>
         <a href="#">Diễn Đàn</a>
     </li>
      <li>
         <a href="#">Giới Thiệu</a>
     </li>
      <li>
         <a href="#">Liên Hệ</a>
     </li>
 </ul>
   </div>      
        
        
    
<form method="post"      enctype="multipart/form-data">
    <label for="file">ID:</label>
    <input type="text"name="id" id="name" value="<?php echo $word['id']; ?>"><br>
    <label for="file">Name:</label>
    <input type="text" name="name" id="company"value="<?php echo $word['name']; ?>"><br>
    <label for="file">URL:</label>
    <input type="text" name="url" id="description"value="<?php echo $word['url']; ?>"><br>
    <label for="file">Name:</label>
    <input type="file" name="file" id="file"><br>
    <input type="submit" name="submit" value="Submit">
</form>


<?php
if (isset($_POST['submit'])) {
    $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if ((($_FILES["file"]["type"] == "image/gif")
            || ($_FILES["file"]["type"] == "image/jpeg")
            || ($_FILES["file"]["type"] == "image/jpg")
            || ($_FILES["file"]["type"] == "image/pjpeg")
            || ($_FILES["file"]["type"] == "image/x-png")
            || ($_FILES["file"]["type"] == "image/png"))
          
            && in_array($extension, $allowedExts)) {
        if ($_FILES["file"]["error"] > 0) {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        } else {
            echo "Upload: " . $_FILES["file"]["name"] . "<br>";
            echo "Type: " . $_FILES["file"]["type"] . "<br>";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
 $file_name = $temp[0] . '-' . time() . '.' . $temp[1]; //
            if (file_exists("./public/images/" . $_FILES["file"]["name"])) {
                echo $_FILES["file"]["name"] . " already exists. ";
            } else {
                move_uploaded_file($_FILES["file"]["tmp_name"], "./public/images/" . $file_name);
                echo "Stored in: " . "./public/images/" . $file_name;
            }
             $array = array(
                "id" => $_GET["id"],
                "img" => "public/image/" . $file_name
            );
            $keyword->update($array);
            $hinh = "./public/image/" .$file_name;
           
            
        }
    } else {
        echo "Invalid file";
    }
    echo"<img src='$hinh' with='50px'>";
}
?></br>

  
<a href="word.php">Quay lại</a>

 <div class="thanh"></div>
        <?php
        $page =1;
        if (isset($_GET['page']))            
        $page = $_GET['page'];
        $from = PER_PAGE*($page-1);
        $to=PER_PAGE;
        $query = "SELECT * FROM works LIMIT $from ,$to";
        $list = $keywords->select($query);
        ?>
    </from>

    
    <div><h1 align="center">Nguyễn Trường Huy-C12TDT</h1></div>

    
   <div class="cuoi"></div>   
</body>
        
</html>     
    